#!/bin/bash

# 取第一个参数
URL=$1
shift

HOST=${URL/:/\/}

# 等 60 秒
CODE=0
for i in {1..60}
do
	timeout 1 bash -c "cat < /dev/null > /dev/tcp/$HOST"
	CODE=$?
	echo $i - $CODE - 等待 $URL
	if [[ "$CODE" == "0" ]]; then
		break
	fi
	sleep 1
done

if [[ "$CODE" == "0" ]]; then
	exec $@
else
	echo $URL 无效，退出运行
fi
